package leetCode.q14;

public class Solution {
    public String longestCommonPrefix(String[] strs) {
        //find the min
        int minlen=strs[0].length();
        for(int i=1;i<strs.length;i++){
            if(minlen>strs[i].length()){
                minlen = strs[i].length();
            }
        }

        //右端点 闭区间
        int r = 0;
        LOOP1:
        for(;r<minlen;r++){
            //对每个右端点，遍历检查前缀和
            char c = strs[0].charAt(r);

            for(int i=0;i<strs.length;i++){
                if(c != strs[i].charAt(r)){
                    break LOOP1;
                }
            }
        }

        return strs[0].substring(0,r);
    }

    public static void main(String[] args) {
        String[] arr = new String[]{"flower","flow","flight"};
        System.out.println(new Solution().longestCommonPrefix(arr)+"---");
    }
}
